package com.ceuer.resttemplate.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GetController {
	
	/**
	 * 不带参的get请求
	 * @return
	 */
	@RequestMapping(value = {"/", "testGet"}, method = RequestMethod.GET)
	public JSONObject testGet() {
		JSONObject result = new JSONObject();
		result.put("code", 200);
		result.put("msg", "请求成功，方法：testGet");
		return result;
	}
	
	/**
	 * 带参的get请求(restful风格)
	 * @return
	 */
	@RequestMapping(value = "testGetByRestFul/{id}/{name}", method = RequestMethod.GET)
	public JSONObject testGetByRestFul(@PathVariable(value = "id") String id, @PathVariable(value = "name") String name) {
		JSONObject result = new JSONObject();
		result.put("code", 200);
		result.put("msg", "请求成功，方法：testGetByRestFul，请求参数id：" + id + ",请求参数name：" + name);
		return result;
	}
	
	/**
	 * 带参的get请求(使用占位符号传参)
	 * @return
	 */
	@RequestMapping(value = "testGetByParam", method = RequestMethod.GET)
	public JSONObject testGetByParam(@RequestParam("userName") String userName, @RequestParam("userPwd") String userPwd) {
		JSONObject result = new JSONObject();
		result.put("code", 200);
		result.put("msg", "请求成功，方法：testGetByParam，请求参数userName：" + userName + ",userPwd：" + userPwd);
		return result;
	}
	
	
}
